package org.lq.us.service.impl;

import org.lq.us.commons.Page;
import org.lq.us.dao.RoelDao;
import org.lq.us.dao.impl.RoelDaoImpl;
import org.lq.us.entity.Role;
import org.lq.us.entity.Users;
import org.lq.us.service.RoleService;

import com.google.gson.Gson;

public class RoleServiceImpl implements RoleService {
	
	RoelDao roleDao = new RoelDaoImpl();
	@Override
	public int save(Role r) {
		return roleDao.save(r);
	}

	@Override
	public int deltet(int id) {
		if(roleDao.getUserCountByRid(id)>0) {
			return -1;
		}
		return roleDao.deltet(id);
	}

	@Override
	public Role getById(int id) {
		return roleDao.getById(id);
	}

	@Override
	public int update(Role r) {
		return roleDao.update(r);
	}

	@Override
	public void findPage(Page<Role> page, String name) {
		if(name == null) {
			name = "";
		}
		roleDao.findPage(page, name);
	}

	@Override
	public int getCount(String name) {
		if(name == null) {
			name = "";
		}
		return roleDao.getCount(name);
	}

	@Override
	public String getPieData() {
		return new Gson().toJson(roleDao.getPieData());
	}

}
